{block name=body} 
{function name=render_list level=0 showReply=0} 
    {assign var='count_post' value=1}
    {foreach $items as $item}
        {if !$query || ($results && ($item.listing_object_id|in_array:$results || $item.listing_parent_id|in_array:$results) ) }
        <tr id="post{$item.listing_object_id}" {if $level eq 0}class="info"{else}class="reply r{$item.listing_parent_id}" {if !$showReply}style="display:none;"{/if}{/if}>
            <td>{$item.listing_seo_title}</td>
            <td>{$item.listing_created|date_format:"%Y-%m-%d"}<br>{$item.listing_created|date_format:"%I:%M%p"}</td>
            <td>{if $admin.level eq 1}<div class="pull-right text-danger"><a href="javascript:void(0)" onclick="deletePost({$item.listing_object_id})"><span class="glyphicon glyphicon-remove"></span></a></div>{/if}{$item.listing_content1}<br>{if $item.listing_image}<br><img src="{$item.listing_image}" class="img-responsive" style="max-width: 500px; max-height: 400px;" alt="image"><br>{/if} {if $item.tags}<small>标签: {foreach from=$item.tags key=id item=tag name=tags} <a href="javascript:void(0)" onclick="window.location.assign( '/admin/list/noticeboard?q={$tag.tag_value}')">{$tag.tag_value}</a>{if !$smarty.foreach.tags.last},{/if}{/foreach}</small><br>{/if}{if $level eq 0}<a href="javascript:void(0)" onclick="GetReplyPostForm('{$item.listing_object_id}');">回复</a>{/if}</td>
            <td>{if $level eq 0}{if count($item.subs) gt 0}<a href="javascript:void(0)" onclick="$('.r{$item.listing_object_id}').toggle(); scrolltodiv( $(this).closest('tr').next());">{count($item.subs)}</a>{else}0{/if}{/if}</td>
        </tr>
            {if $error.reply && $error.object_id eq $item.listing_object_id}{include file="reply-form.tpl" listing_parent_id=$error.object_id }{/if}
        
            {if count($item.subs) > 0} 
                {if $post.replied_to eq $item.listing_object_id}{assign var='showReply' value=1}{else}{assign var='showReply' value=0}{/if}
                {call name=render_list items=$item.subs level=$level+1 showReply=$showReply} 
            {/if} 
            {if $level eq 0}{if $count_post lt 10 }{assign var='count_post' value=$count_post+1}{else}{if !$show_all && !$count}{assign var='view_all' value=1}{break}{/if}{/if}{/if}
        {/if}
    {/foreach}
    {if $view_all}<tr class="text-center"><td colspan="4"><a href="javascript:void(0)" onclick="window.location.assign( '/admin/list/noticeboard?show_all=1')">View all</a></td></tr>{/if}
    
{/function}

<div class="row">
    <div class="col-sm-12">
        <h2 class="title">{$zone}</h2>
    </div>
</div>
<div id="new-post-wrapper">
    <h3 class="text-center">发布一个新的信息或问题</h3>
    <form class="form-horizontal form" id="NewPost-form" role="form" accept-charset="UTF-8" action="/admin/includes/processes/processes-noticeboard.php" method="post" enctype="multipart/form-data">
        <input type="hidden" value="NewPost" name="action"/> 
        <input type="hidden" name="formToken" value="{$token}" id="formToken"/>

        <div class="row form-group">
            <label for="listing_content1" class="col-sm-3 control-label">信息*</label>
            <div class="col-sm-6">
                <textarea class="form-control clear-saved" name="listing_content1" id="listing_content1" required>{$post.listing_content1}</textarea>
            </div>
        </div>
        <div class="row form-group">
                <label class="col-sm-3 control-label" for="uploadphoto">图片</label>
            <div class="col-sm-9">
                 <input type="file" id="uploadphoto" name="file" class="upload">
        <div class="text-left"><small>(3MB max. - Only .jpeg, .jpg, .png and .gif)</small></div>
            </div>                                
        </div>
        <div class="row form-group">
            <label for="walkin_phone" class="col-sm-3 control-label">标签</label>
            <div class="col-sm-6">
                <input type="text" class="form-control clear-saved" name="tags" value="{$post.tags}" id="tags" /> 
                <div class="text-left"><small>对个标签之间用逗号进行分隔</small></div>
            </div>
        </div>
        <div class="text-center">
            {if $error.post}
                <div class="error-alert">
              <div class="alert alert-danger fade in">
                        <button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
                        <strong>{$error.post}</strong>
                    </div>
            </div>
        {/if}
            <button type="submit" onclick="if($('#NewPost-form').valid()) { $(this).hide(); $('#posting').show(); }" class="btn btn-default">确认发布</button>
            <span id="posting" style="display:none"><b>提交中...</b></span>
        </div>
    </form>
</div>
<br><br>
<hr>
<div class="row" id="notice">
    {if $notice}
    <div class="success-alert text-center">
        <div class="alert alert-success fade in">
            <button class="close" aria-hidden="true" type="button"  onclick="$(this).closest('.success-alert').fadeOut('slow');">&times;</button>
            <strong>{$notice}</strong>
        </div>
    </div>
    {/if}
    <form class="form-inline form" role="form" accept-charset="UTF-8" action="" method="get">
        <div class="col-sm-12 form-group text-center">
            <label for="searchpost" class="sr-only">搜索</label>
            <input type="text" class="form-control clear-saved" name="q" value="" id="searchpost"/> 
            <button type="submit" class="btn btn-default">搜索</button>
        </div>
    </form>
    <br>
    <br>
    {if $query}
    <div class="col-sm-12 text-center text-info">
        <h3 id="result">{$count} result(s) found for '{$query}'</h3>
    </div>
    <br>
    {/if}
    {if !$query || ($query && $count gt 0) }
    <table id="noticeboard-table" class="table table-bordered table-striped table-hover">
        <thead>
            <tr class="info">
                <th>用户名</th>
                <th>发布时间</th>
                <th>消息/问题</th>
                <th>回复</th>
            </tr>
        </thead>
        <tbody>{call name=render_list items=$list}
        </tbody>
    </table>
    {/if}
</div>
{/block}

{block name=tail}
    <script type="text/javascript">
    
    $(function() {    
            $('#NewPost-form').validate();

        {if $query && !$notice && !$error}
            scrolltodiv('#result');
        {/if}
    });

    
    function scrolltodiv(ID){
        $('html,body').animate({
            scrollTop : $(ID).offset().top
        });
    }
    
    function deletePost(ID){
        if(confirm('Do you want to delete the post?')){
            $('body').css('cursor', 'wait');
            $.ajax({
                type : "POST",
                url : "/admin/includes/processes/processes-noticeboard.php",
                cache : false,
                data : 'action=DeletePost&listing_object_id='+ID+'&formToken='+$("#formToken").val(),
                dataType : "html",
                success : function(data, textStatus) {
                    try {
                        var obj = $.parseJSON(data);
                        if (obj.success){
                             $('#post'+ID).hide('slow').remove();
                         }
                    } catch (err) {}
                    $('body').css('cursor', 'default');
                },
                error: function(){
                    $('body').css('cursor','default'); 
                    console.log('AJAX error');
              }
            });
        }
    }
    
    function GetReplyPostForm(ID){
        $('body').css('cursor', 'wait');
        $.ajax({
            type : "POST",
            url : "/admin/includes/processes/processes-noticeboard.php",
            cache : false,
            data : 'action=GetReplyPostForm&listing_parent_id='+ID+'&formToken='+$("#formToken").val(),
            dataType : "html",
            success : function(data, textStatus) {
                try {
                    var obj = $.parseJSON(data);
                    if (obj.success){
                         $('#post'+ID).after(obj.template);
                     }
                } catch (err) {}
                $('body').css('cursor', 'default');
            },
            error: function(){
                $('body').css('cursor','default'); 
                console.log('AJAX error');
          }
        });
    }
    
    </script>

{/block}